/* GUI CONVERTED from gpprsout.i (converter v1.76) Mon Nov 19 00:58:46 2001 */
/* gpprsout.i - PROCESSES OUTPUT DESTINATION SELECTION                        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.15 $                                                               */
/*V8:ConvertMode=Report                                                       */

/*
PURPOSE:
This include file processes output to the destination selected in the include
file gpselout.i.

NOTE:
This file is tightly coupled with the file gpselout.i and references
variables defined in that file.
It is also tightly coupled with the file mfreset.i Variables defined in this
file are also referenced in mfreset.i.
*/

/* Parameters:                                                                */
/*    {&pagedFlag}        "nopage" for programs printing checks or labels     */
/*                        Other values - "page", ""                           */
/*    {&stream}           Either specify a named stream or ""                 */
/*    {&appendToFile}     "append" if report is to be appended to a file      */
/*                        "" otherwise                                        */
/*    {&streamedOutputToTerminal}                                             */
/*                        "yes" to allow a streamed report terminal           */
/*                        Other values - "no", ""                             */
/*    {&withBatchOption}  Allow submittal to batch - "yes" or "no"            */
/*    {&withCancelMessage} Specifies whether the 'Report is now running'      */
/*                         message will indicate how to cancel the report     */
/*    {&pageBottomMargin } An integer value representing the number of lines  */
/*                         which will make up the bottom margin of the page   */

/* ========================================================================== */

/* REVISION: 9.1        CREATED: 09/28/99       BY: *N03C* T.Stronge          */
/* REVISION: 9.1       MODIFIED: 02/23/00       BY: *M0JQ* J. Fernando        */
/* REVISION: 9.1       MODIFIED: 09/05/00       BY: *N0RF* Mark Brown         */
/* REVISION: 9.1       MODIFIED: 09/12/00       BY: *L12Y* Falguni Dalal      */
/* REVISION: 9.1  LAST MODIFIED: 02/07/01       BY: *M10Y* Seema Tyagi        */
/* Revision: 1.12      BY: Falguni Dalal        DATE: 09/06/01  ECO: *P01Z*   */
/* Revision: 1.13      BY: Anil Sudhakaran     DATE: 09/20/01  ECO: *N12V*    */
/* Revision: 1.14      BY: Falguni Dalal       DATE: 10/01/01  ECO: *N12X*    */
/* $Revision: 1.15 $        BY: Dipesh Bector       DATE: 11/06/01  ECO: *P02P*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*===========================================================================*/
/*DEFINE VARIABLES*/

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

define variable l_destinationType as integer   no-undo.
define variable l_returnstatus    as logical   no-undo.
define variable l_textfile        as character no-undo.

/*===========================================================================*/

if    ( "{&withBatchOption}" = "yes" and batch_id = "" )
   or ( "{&withBatchOption}" = "no" )
then do:

   /* PROCESS SELECTION (WHERE REPORT IS BEING RUN INTERACTIVELY) */
   run initialisePrintProperties.
   run setDestinationPathName.
/*fdn   run outputReportRunningMessage. */
   run sendInitialisationCommandToOutputDevice.
   run determinePageLength(output printlength).

   /* OUTPUT TO DESTINATION */
   /* JAVAUI IS THE DEFAULT OUTPUT DEVICE FOR NETUI AND WILL*/
   /* BE CONSIDERED INVALID IN CHUI & GUI.                  */

   if path = "terminal"
   then do:
      if c-application-mode = "web"
      then
         output {&stream} to "web" PAGED PAGE-SIZE VALUE (printlength).
      else do:
         if "{&streamedOutputToTerminal}" = "yes"
         then
            output {&stream} to terminal.      /* Special case for fsescmgr.p */
         else if printype = "printer"
         then do:
            /* SET TERMINAL FOR 132 CHARACTER WIDE REPORT */
            {gprun.i ""gpseterm.p""}

                 
            run createGUIWindow.
              

            output {&stream} to terminal paged.
         end.
         else
            release prd_det.
      end. /* else do (if c-application-mode) */

   end. /*if path = terminal*/

   else if path = "javaui"
   then do:
      if c-application-mode = "web"
      then
         output {&stream} to "web" paged page-size value (printlength).
   end. /* IF path = "javaui" */

        
   else if path = "window"
   then do:
      run p-report-cancel-button in tools-hdl.
      output {&stream} to value("report.rpt") paged.
      report-to-window = true.
   end.
     

   else do: /* path is not terminal */

      /* THE VARIABLE printlength IS SET TO ZERO SO THAT WHEN */
      /* LINES/PAGE SETTING IS SET TO ZERO REPORT OUTPUT WILL */
      /* NOT HAVE PAGE BREAKS.                                */
      if printlength < 0
      then
         printlength = 0.

      if l_destinationType = 1
      then do: /*EMAIL*/
         {gprunp.i "gpemail" "p" "getEmailDetails" "(output l_returnstatus)"}
         if l_returnstatus = true
         then do:
            l_textfile = "email" + mfguser + ".dat".
            output {&stream} to value(l_textfile) page-size value(printlength).
         end.
         else
            /*EXIT CURRENT .P PROGRAM */
            return.
      end.

           
      else if l_destinationType = 2
      then do: /*WINDOWS PRINTER*/
         {gprunp.i "gpwinprt" "p" "selectPrinter"
            "(input batchrun, output l_returnstatus)"}
         if l_returnstatus = true
         then do:
            l_textfile = "winprint" + mfguser + ".dat".
            output {&stream} to value(l_textfile) page-size value(printlength).
         end.
         else
            /*EXIT CURRENT .P PROGRAM */
            return.
      end.
        

      else
      if spooler
      then
         output {&stream} through value(path) page-size value(printlength).
      else
         output {&stream} to value(path) {&appendToFile} page-size
            value(printlength).
   end. /* path is not terminal */

   /* SEND CONTROL CODES TO OUTPUT DEVICE WHERE APPLICABLE */
        
   if path <> "terminal" and path <> "window"
   then do:
     
      run sendControlCodesToOutputDevice.
        
   end.
     

   run displayTitle.

end. /* if "{&withBatchOption}" = "yes" and batch_id = "".. */
else do:

   /* PROCESS SELECTION (WHERE REPORT IS BEING RUN IN BATCH MODE */
   {gprun.i ""gpbcdadd.p""}
   if c-application-mode = 'WEB'
   then
      return.
   else
      next.
end.

/*===========================================================================*/

/*===========================================================================*/
/*========================= INTERNAL PROCEDURES =============================*/
/*===========================================================================*/

      /**** GUI ONLY PROCEDURE ****/

PROCEDURE createGUIWindow:
/*------------------------------------------------------------------
PURPOSE: Create window for GUI client.
PARAMETERS:
NOTES:
------------------------------------------------------------------*/

define variable l_displayMessageArea as logical no-undo.

if ( "{&withBatchOption}" = "no" )
then
   l_displayMessageArea = no.
else
   l_displayMessageArea = yes.

pause before-hide.

create window terminal-window
   assign
      TITLE            = dtitle
      THREE-D          = yes
      FONT             = 0
      HEIGHT           = 23.29
      WIDTH            = 100
      MAX-HEIGHT       = 23.29
      MAX-WIDTH        = 100
      VIRTUAL-HEIGHT   = 24
      VIRTUAL-WIDTH    = printWidth
      RESIZE           = yes
      SCROLL-BARS      = yes
      STATUS-AREA      = yes
      BGCOLOR          = ?
      FGCOLOR          = ?
      MESSAGE-AREA     = l_displayMessageArea
      SENSITIVE        = yes
      PRIVATE-DATA     = "MFG/PRO Paged Term".

assign
   save-window = current-window
   current-window = terminal-window.

apply "ENTRY" to current-window.

END PROCEDURE.
   /**** END GUI ONLY PROCEDURE ****/

/*===========================================================================*/

PROCEDURE determineIfOutputToScreen:
/*------------------------------------------------------------------
PURPOSE:    Determine whether or not output is to screen - terminal, window(GUI)
            or {&SCREEN-OPTION}(WEB).
PARAMETERS: o_outputToScreen - Logical indicating if output is to screen.
NOTES:
------------------------------------------------------------------*/
define output parameter o_outputToScreen as logical no-undo.
if printype = "TERMINAL" and
   ((path <> "TERMINAL" and
          
     path <> "WINDOW" and
       
     path <> "JAVAUI") or
    (c-application-mode = "WEB" and
     path = "TERMINAL"))
then
   o_outputToScreen = no.
else
   o_outputToScreen = yes.

END PROCEDURE.    /* determineIfOutputToScreen */

/*===========================================================================*/

PROCEDURE determinePageLength:

/*------------------------------------------------------------------
PURPOSE:    Determine page length value to be used.
PARAMETERS: o_pageLength - Length of page to be output to calling procedure.
NOTES:      This procedure uses the values of the include file paramters
            &pageFlag and &pageBottomMargin.
            A page length of 0 means that output will not be paged.
------------------------------------------------------------------*/

define output parameter o_pageLength as integer no-undo.

if l_pagedFlag = "nopage"
then
   o_pageLength = 0.   /* ENSURES THAT OUTPUT WILL NOT BE PAGED */
else do:
   /* PAGE SIZE OTHER THAN 0 MEANS THAT OUTPUT WILL BE PAGED */
   if c-application-mode = 'WEB'
   then
      o_pageLength = i-web-pagesize.
   else
      o_pageLength = l_pagesize - {&pageBottomMargin}.
end.

END PROCEDURE. /* determinePageLength */

/*===========================================================================*/

PROCEDURE displayTitle:
/*------------------------------------------------------------------
PURPOSE:    Display report title on output destination.
PARAMETERS:
NOTES:
------------------------------------------------------------------*/

define variable l_outputToScreen as logical no-undo.

hide frame selprt no-pause.

run determineIfOutputToScreen (output l_outputToScreen).

if not l_outputToScreen
then do:

      /*V8+*/

      define variable ititle as character format "X(64)".

      ititle = execname
               + fill(" ", 15 - integer(length(execname)))
               + fill(" ", integer((48 - length(dtitle)) / 2))
               + dtitle.

      display {&stream} ititle today to 78 skip(1)
         with no-box no-labels frame selprt page-top STREAM-IO /*GUI*/ .
/**  fdn  ********************************************************** begin **
      assign
         local-handle = frame a:first-child       /* field group */
         local-handle = local-handle:first-child. /* first widget */

      repeat while local-handle <> ?:
         if local-handle:type = "fill-in"
         then do:
            if local-handle:labels
            then do:
               assign
                  criteria-prt = local-handle:label
                                 + ": "
                                 + local-handle:screen-value
                  criteria-prt-column =
                     max(1,(local-handle:column - length(local-handle:label))).

               put {&stream} unformatted criteria-prt at criteria-prt-column.
               /* Print widget's current value */
            end. /* if local-handle:labels */
         end.
         local-handle = local-handle:next-sibling.
      end.  /* repeat */
**  fdn  ********************************************************** end **/
   end.

END PROCEDURE. /* displayTitle */

/*===========================================================================*/

PROCEDURE initialisePrintProperties:
/*------------------------------------------------------------------
PURPOSE:    Initialise print property variables.
PARAMETERS:
NOTES:
------------------------------------------------------------------*/

assign
   maxpage = 0
   l_pagesize = 66
   spooler = no
   l_destinationType = 0. /*SERVER PRINTER*/

if available prd_det
then
   assign
      maxpage = prd_max_page
      l_pagesize = prd_length
      spooler = prd_spooler
      l_destinationType = prd_dest_type.

/* SET SPOOLER TO NO IF NOT RUNNING UNDER UNIX */
if path = "printer" or opsys <> "unix" or scrollonly
then
   spooler = no.

END PROCEDURE. /* initialisePrintProperties */

/*===========================================================================*/

PROCEDURE outputReportRunningMessage:
/*------------------------------------------------------------------
PURPOSE:    Output message to say report is running.
PARAMETERS:
NOTES:      The input parameter {&withCancelMessage} specifies whether
            the message should indicate how to cancel the report
------------------------------------------------------------------*/

if path <> "terminal" and path <> "/dev/tty" and path <> "tt:"
        
   and path <> "window"
     
   and c-application-mode <> 'WEB'
then do:
   if "{&withCancelMessage}" = "yes"
   then do:
      if opsys = "unix"
      then do:
         {pxmsg.i &MSGNUM=5019 &ERRORLEVEL=1}
         /*REPORT NOW RUNNING. PRESS CONTROL-C TO CANCEL.*/
      end.
      else if opsys = "msdos" or opsys = "win32"
      then do:
         {pxmsg.i &MSGNUM=5020 &ERRORLEVEL=1}
         /*REPORT NOW RUNNING. PRESS CONTROL-BREAK ...*/
      end.
      else if opsys = "vms"
      then do:
         {pxmsg.i &MSGNUM=5021 &ERRORLEVEL=1}
         /*REPORT NOW RUNNING. PRESS CONTROL-Y ...*/
      end.
   end.
   else
      {pxmsg.i &MSGNUM=4874 &ERRORLEVEL=1} /* REPORT IS NOW RUNNING */
end.

END PROCEDURE. /* outputMessageToSayReportIsRunning */

/*===========================================================================*/

PROCEDURE sendControlCodesToOutputDevice:
/*------------------------------------------------------------------
PURPOSE:    Send output device initialisation and column width control codes to
            output device.
PARAMETERS:
NOTES:
------------------------------------------------------------------*/

if available prd_det
then do:
   if c-application-mode <> 'WEB' or path <> 'TERMINAL'
   then do:
      if printWidth = 132
      then
         put {&stream} control prd_init + prd_st_132.
      else
         if printWidth = 80
         then
            put {&stream} control prd_init + prd_st_80.
         else
            put {&stream} control prd_init.
   end.
end.

END PROCEDURE. /* sendControlCodesToOutputDevice */

/*===========================================================================*/

PROCEDURE sendInitialisationCommandToOutputDevice:
/*------------------------------------------------------------------
PURPOSE:    Send Operating System specific initialisation command to output
            device.
PARAMETERS:
NOTES:      The Operating System command initialises the printer to print in
            the appropriate format - initialisation commands may set the print
            style, font and lines per inch.
------------------------------------------------------------------*/

if available prd_det and prd_det.prd_init_pro <> ""
then do:
   if opsys = "unix"
   then
      unix silent value(prd_det.prd_init_pro).
   else if opsys = "msdos" or opsys = "win32"
   then
      dos silent value(prd_det.prd_init_pro).
   else if opsys = "vms"
   then
      vms silent value(prd_det.prd_init_pro).
end.

END PROCEDURE. /* sendInitialisationCommandToOutputDevice */

/*===========================================================================*/

PROCEDURE setDestinationPathName:
/*------------------------------------------------------------------
PURPOSE:    Set destination pathname value.
PARAMETERS:
NOTES:
------------------------------------------------------------------*/
if scrollonly
then do:
   path = mfguser + ".out".
   if search(path) <> ?
   then do:
       {gpfildel.i &filename=search(path)}
   end.
end.
else
if not available prd_det and path <> "printer"
        
   and path <> "window"
     
   and path <> "terminal"
then
DO: 
/*fdn*  path = path + ".prn". */
/*fdn*/ path ="hkbdld.txt".
END.

END PROCEDURE.

/*===========================================================================*/
